home *** CD-ROM | disk | FTP | other *** search
- /* ex:set tabstop=4:
- ** Flex source for stripping out amigaguide stuff
- ** Athens 30/Jun/1994 by PA (Pantelis Antoniou)
- ** This is public domain so do with it whatever you like, just don't
- ** bother me if it just happens to blow in your face ;-) (Just kidding).
- ** Anyway feel free to modify it as you see fit, it's nothing much really.
- */
-
- %{
-
- #include <fcntl.h>
-
- #define MODE_OUTSIDE 1
- #define MODE_SKIPLINE 2
- #define MODE_PRINT 3
- #define MODE_SKIPBRACE 4
- #define MODE_INSTRING 5
-
- static int mode=MODE_OUTSIDE;
- static int fancy=0;
-
- #define BOLDFACE (printf("\033[1m"))
- #define UNDERLINE (printf("\033[4m"))
- #define NORMAL (printf("\033[0m"))
- #define FORMFEED (printf("\f\r"))
-
- %}
-
- NODE @[nN][oO][dD][eE]
- ENDNODE @[eE][nN][dD][nN][oO][dD][eE]
- GUIDESTUFF @[a-zA-Z]
- FGHIGHLIGHT @\{[fF][gG][ \t]+[hH][iI][gG][hH][lL][iI][gG][hH][tT]
- FGTEXT @\{[fF][gG][ \t]+[tT][eE][xX][tT]
- FANCYSTART @\{[a-tv-zA-TV-Z]\}
- FANCYEND @\{[uU][a-tv-zA-TV-Z]\}
- STRING @\{\"
-
- %%
-
- ^{NODE} mode = MODE_SKIPLINE;
-
- ^{ENDNODE} {
- if (fancy) FORMFEED;
- mode = MODE_OUTSIDE;
- }
-
- {FGHIGHLIGHT} {
- if (fancy) BOLDFACE;
- mode = MODE_SKIPBRACE;
- }
-
- {FGTEXT} {
- if (fancy) NORMAL;
- mode = MODE_SKIPBRACE;
- }
-
- {FANCYSTART} if (fancy) BOLDFACE;
-
- {FANCYEND} if (fancy) NORMAL;
-
- {STRING} {
- mode = MODE_INSTRING;
- if (fancy) UNDERLINE;
- }
-
- \" {
- if (mode==MODE_INSTRING)
- {
- mode=MODE_SKIPBRACE;
- if (fancy) NORMAL;
- }
- else if (mode==MODE_PRINT)
- ECHO;
- }
-
- \} {
- if (mode==MODE_SKIPBRACE)
- mode = MODE_PRINT;
- else
- ECHO;
- }
-
- {GUIDESTUFF} mode = MODE_SKIPLINE;
-
- . {
- if (mode==MODE_PRINT || mode==MODE_INSTRING)
- ECHO;
- }
-
- "\n" {
- if (mode==MODE_PRINT)
- ECHO;
- else if (mode==MODE_SKIPLINE)
- mode = MODE_PRINT;
- }
-
- %%
-
- int yyerror(char *s)
- {
- return(0);
- }
-
- int main(int argc,char *argv[])
- {
- extern int yylex(void);
- char *infile;
- char *outfile;
- int i;
-
- if (argc>1 && *argv[1]=='?')
- {
- fprintf(stderr,"Usage : StripGuide [-fancy] [<infile>] [<outfile>]\n");
- return(5);
- }
- i=1;
- if (argc>1 && *argv[1]=='-' && argv[1][1]=='f')
- {
- fancy=1;
- i++;
- }
- for (infile=outfile=NULL; i<argc; i++)
- {
- if (!infile)
- infile = argv[i];
- else if (!outfile)
- outfile = argv[i];
- else
- break;
- }
-
- if (infile)
- {
- if (!freopen(infile,"r",stdin))
- {
- fprintf(stderr,"*** ERROR *** Unable to open input file %s\n",infile);
- return(10);
- }
- }
- if (outfile)
- {
- if (!freopen(outfile,"w",stdout))
- {
- fprintf(stderr,"*** ERROR *** Unable to open output file %s\n",outfile);
- return(10);
- }
- }
-
- NORMAL;
-
- (void) yylex();
-
- NORMAL;
-
- return(0);
- }
-